package com.knight.admin.service;

import java.util.Date;

import com.jfinal.plugin.activerecord.Page;
import com.knight.admin.model.Content;

public class NewsService {
	private static NewsService instance = new NewsService();

	private NewsService() {
	}

	public static NewsService getInstance() {
		return instance;
	}

	private final static Content dao = new Content().dao();

	public Page<Content> queryContents(int pageNumber, int pageSize, String type) {
		return dao.paginate(pageNumber, pageSize, "select id,title,type,createDate",
				" from content where type=" + type + " ORDER BY createDate DESC");
	}

	public Content findById(Integer id) {
		return dao.findById(id);
	}
	
	public boolean saveOrUpdate(Content content,String dynamicContent){
		content.setCreateDate(new Date());
		content.setContent(dynamicContent);
		if(content.getId()==null){
			return content.save();
		}else{
			return content.update();
		}
	}
	
	public boolean delete(Integer id){
		return dao.deleteById(id);
	}
}
